<?php TPL::output('global/header.tpl.htm'); ?>

<div class="bd"> 
  <!--right_nav_s--> 
  <!--问题注释_s-->
  <div class="tommy_rightDiv" id="con_0">
    <ul class="yquestionTag" style="border-top:none;">
      <li><strong>问题发布指南</strong></li>
    </ul>
    <div class="company_pro txt" id="con_0">
      <p><b><em>●</em>问题标题：</b> 请用准确的语言描述您发布的问题思想，并控制在 40 个字数以内。</p>
      <p><b><em>●</em>问题补充：</b> 详细补充您的问题内容，并提供一些相关的素材以供参与者更多的了解您所要问题的主题思想</p>
      <p><b><em>●</em>选择话题：</b> 选择一个或者多个合适的话题，让您发布的问题得到更多有相同兴趣的人参与。如果系统没有相关话题，您可以选择创建新的话题。所有人可以在您发布问题之后添加和编辑该问题所属的话题。</p>
      <p><b><em>●</em>修改时效：</b> 在问题发布后的 <?php echo get_setting('question_edit_time');?> 分钟以内可以修改问题内容，超过 <?php echo get_setting('question_edit_time');?> 分钟后将无法再次修改。</p>
    </div>
  </div>
  <!--问题注释_e--> 
  <!--right_nav_e--> 
  <!--left_nav_s-->
  <div class="contant_left">
    <h2 class="c_title"><span class="s"><img src="<?php echo G_STATIC_URL; ?>/common/a_l_04.png"/>发起问题</span><!-- <a href="#question" id="publish_question">问题</a>--></h2>
    <form action="publish/ajax/<?php if ($this->question_info['question_id']) { ?>modify<?php } else { ?>publish<?php } ?>_question/" method="post" id="question_form" onsubmit="return false;">
      <input type="hidden" name="post_hash" value="<?php echo new_post_hash(); ?>" />
      <input type="hidden" name="attach_access_key" value="<?php echo $this->attach_access_key; ?>" />
      <input type="hidden" name="question_id" id="question_id" value="<?php echo $this->question_info['question_id']; ?>" />
      <input type="hidden" name="ask_user_id" value="<?php echo $_POST['ask_user_id']; ?>" />
      <ul class="discussion_element" id="layer0">
        <li>
          <label>问题标题：</label>
          <input name="question_content" class="lx" type="text" value="<?php echo $this->question_info['question_content']; ?>"<?php if(get_setting('question_title_limit') > 0 ){ ?> maxlength="<?php echo get_setting('question_title_limit'); ?>"<?php } ?> />
        </li>
        <li>
          <label>问题补充：</label>
          <textarea class="lx" name="question_detail" id="specificx" style="height: 320px;"  />
          <?php echo $this->question_info['question_detail']; ?>
          </textarea>
        </li>
        <li class="disabled">
          <label>问题分类：</label>
          <select name="category_id">
            <option value="0">- 请选择分类 -</option>
            <?php echo $this->question_category_list; ?>
          </select>
        <li>
          <?php if (get_setting('upload_enable') == 'Y') { ?>
        <li class="line">
          <label>上传附件：</label>
          <div id="file_uploader_question" class="_ajax_uploader userUploadDate"></div>
          <div style="clear:left"></div>
        </li>
        <?php } ?>
        <li class="line"<?php if ($this->question_info['question_id']) { ?> style="display:none"<?php } ?>>
          <label>添加话题：</label>
          <div class="shd" id="Manytopics">
            <div id="addtxt" class="add_C hide"> </div>
            <a title="话题编辑" onclick="hide('editorInput','editor','editorInput','editor hide',this)" id="editor" class="editor" href="javascript:void(0);" title="点击为该问题添加话题">添加话题</a>
            <div id="editorInput" class="editorInput hide" style="padding-top:0;">
              <div class="hide" id="ajaxDate" style="top:29px;">
                <div onclick="add('take');" class="add">添加 <span id="take"></span>话题</div>
                <div id="txt"></div>
              </div>
              <input type="text" name="addName" class="i_add" id="ajaxValue_txt">
              <a onclick="hide('editor','editorInput','editor ','editorInput hide',this);addElementVALUE();" class="default_blue_but" href="javascript:void(0);">完成</a>
              <p class="cr hide" id="err">请勿重复添加话题！</p>
            </div>
          </div>
        </li>
        <?php if ($this->human_valid) { ?>
        <li>
          <label>验证码：</label>
          <input type="text" class="default_autoCode">
          &nbsp;&nbsp;<span class="default_aotoNum"><img id="captcha" onclick="this.src = G_BASE_URL + '/account/captcha/rnd-' + Math.random();" title="点击换一张" src=""></span><a  href="javascript:;" title="点击换一张" onclick="$('#captcha').click();">换一张</a>
        </li>
        <?php } ?>
        <li style="padding-left:0;position:static;width:715px;"><a href="#" onclick="ajax_post($('#question_form')); return false;" class="sureSubMit">确定发布</a></li>
      </ul>
    </form>
  </div>
  <!--left_nav_e--> 
</div>
<script type="text/javascript">
	var ATTACH_ACCESS_KEY = '<?php echo $this->attach_access_key; ?>';
	var QUESTION_ID = document.getElementById('question_id').value;
	
	if (!window.location.hash)
	{
		window.location.hash = 'question';
	}
	
	$(document).ready(function () {
		if (document.getElementById('captcha'))
		{
			document.getElementById('captcha').click();
		}
		
		init_fileuploader('file_uploader_question', G_BASE_URL + '/publish/ajax/question_attach_upload/attach_access_key-' + ATTACH_ACCESS_KEY);
		
		if (QUESTION_ID && G_UPLOAD_ENABLE == 'Y')
		{
			if ($("#file_uploader_question ._ajax_upload-list").attr('class'))
			{
				$.post(G_BASE_URL + '/question/ajax/question_attach_edit_list/', "question_id=" + QUESTION_ID, function (data) {
					if (data['err'])
					{
						alert(data['err']);
						
						return false;
					}
					else
					{
						$.each(data['rsm']['attachs'], function(i, v)
						{
							_ajax_uploader_append_file("#file_uploader_question ._ajax_upload-list", v);
						});
					}
				}, 'json');
			}
		}
		
		if (window.location.hash && $('#' + window.location.hash.replace('#', '')))
		{
			$('#' + window.location.hash.replace('#', '')).click();
		}
				
		
		switch (window.location.hash)
		{
			case '#question':
				$('#publish_' + window.location.hash.replace('#', '')).click();
			break;
		}
	});	



var _spex = _$("specificx")._$id();
var _fouc = "onfocus",_blur = "onblur",changeEvent = 'onkeydown' && 'onkeyup',
    changesEvent = function (){
		
		if(this.getAttribute("id") == 'specificx'){
			if(this.scrollHeight >= 500){
				
				this.style.height = '500px';
				this.style.overflowY = 'auto';
				return false;
			}
			
			
			this.style.height = '0px';
			if(this.scrollHeight >=320){
			
				this.style.height = '0px';
				this.style.height = this.scrollHeight + 50 + 'px';
				
			}else{
				
				this.style.height = '320px';
			}
				
		}else{
			
			if(this.scrollHeight >= 500){
				
				this.style.height = '500px';
				this.style.overflowY = 'auto';
				return false;
			}
			this.style.height = '0px';
			this.style.height = this.scrollHeight + 60 + 'px';
		}
		
	 },
	 elementEventFocus = function(){
		
		if(this.value == ''){
			if(this.getAttribute("id") == 'specificx'){
				this.style.height = '320px';
				
			}else{
				this.style.height ='80px';
			}
		}
		
		
	 },
	
	elementEventblur = function(){
	
		if(this.value==''){
			if(this.getAttribute("id") == 'specificx'){
				this.style.height = '320px';
			}else{
				this.style.height ='80px';
			}
		
		}
	};
	
	if(_spex){
	
		_spex[changeEvent] = changesEvent; //绑定change事件
		_spex[_fouc] = elementEventFocus;
		_spex[_blur] = elementEventblur;
	}


function hide(o,j,c,p,x){
	
	var addtxt = d.getElementById("addtxt");
	
	var x = d.getElementById(o);
	var xjx = d.getElementById(j);
		x.className = c;
		xjx.className = p;
}

function addElementVALUE(){

		var inps = d.getElementById('editorInput').getElementsByTagName("input")[0],classname=null;
		var addtxt = d.getElementById('addtxt');
		var s_span = addtxt.getElementsByTagName("span");
		
		if(inps.className =='i_add'){
			
			classname = inps;
		}
		
		var inpsValue = classname.value;//.replace(/\s/g,'');
		
		if(inpsValue==''){return false;}
		
		for(var xi = 0,len = s_span.length; xi <len ; xi++){
			
			var s = s_span[xi];
			if(s.getAttribute("val") == inpsValue){
				
				return false;
			}
		}
		var a = '<a href="' + G_BASE_URL + '/topic/'+inps.value+'">'+inpsValue+'</a>';		
		var s = d.createElement("span");
			s.setAttribute("val",inpsValue);
			s.innerHTML = a+'<em onclick="removeChilds(this);">x</em><input type="hidden" name="topics[]" value="'+inpsValue+'" />';
			d.getElementById('addtxt').appendChild(s);
			d.getElementById('addtxt').className = 'add_C'
			inps.value ='';

}



var removeChilds = function(el){
		var parent = el.parentNode.parentNode;
		parent.removeChild(el.parentNode);
		var s = parent.getElementsByTagName('span');
		if(s.length <=0){
			parent.className = 'add_C hide';
		}else{
			parent.className = 'add_C';
		}
	}
var t;
var m = {
	
		mx : function (){
			
			var doc = document, 
				mxId = document.getElementById("Manytopics"),
				ajaxDate = document.getElementById("ajaxDate"),
				take = document.getElementById("take"),
				txt = document.getElementById("txt"),
				addtxt = document.getElementById("addtxt");
			
			var mxinput = document.getElementById("ajaxValue_txt");
			var mxDiv = mxId.getElementsByTagName("div")[0];
			var mxSpan = mxDiv.getElementsByTagName("span");
			
			
			
			var el = this;
			
			return {
			
				add : function (a,val){
				
					var s = doc.createElement("span");
						s.innerHTML = a+'<em onclick="removeChilds(this);">x</em><input type="hidden" name="topics[]" value="'+val+'" />';	
						s.setAttribute('val',val);			
						return s ;
				
				},
				
				app : function (x){
				
						var objValue = x.getAttribute("date-list");
						
						var v = addtxt.getElementsByTagName("span");
								
							for(var i = 0,len = v.length; i < len ; i++ ){
								if(v[i].getAttribute("date-list") == objValue){
									mxinput.classNam ='i_add inErr';
									mxinput.value ='';
									doc.getElementById("err").innerHTML ='请勿重复添加话题！';
									doc.getElementById("err").className = 'cr';
									return false;
								}
							}
						
						var el = this;
						
						var a = '<a href="javascript:;">'+objValue+'</a>';	
						var s = el.add(a,objValue);
							mxDiv.appendChild(s);	
							ajaxDate.className = 'hide';
							mxinput.value ='';
							mxinput.focus();
							doc.getElementById('addtxt').className = 'add_C'
						
				
				},
				
				ev : function(){
					var elx = this;
					
					mxinput['onkyedown' && 'onkeyup'] = function(){
						
						mxinput.classNam ='i_add';
						doc.getElementById("err").className = 'cr hide';
						if(this.value.replace(/\s/g,'') =='') {ajaxDate.className = 'hide';return false;}
						var xmlvalue,XHR;
						var objValue = this.value ;
						var strValue = objValue.toString();
						var stv = strValue.replace(/\s/g,'');
						take.setAttribute("date-list",stv); 
						take.innerHTML = stv;
						var url = G_BASE_URL + '/search/ajax/search/type-topic_add__q-'+stv+'__limit-100';

						
							XHR = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("microsoft.XMLHTTP");
							XHR.open("GET",url,true); 
							XHR.onreadystatechange = function(){
							
							 if( XHR.readyState == 4 && XHR.status == 200 ){  
									
										ajaxDate.className ='';
									if(XHR.responseText.length >2){
										
										
										txt.getAttribute('class') == 'hide' ? txt.className = '' : '';
										xmlvalue = XHR.responseText;
										var x = new Function('return'+xmlvalue)();
										
										for(var i=-1,len= x.length; ++i<len;){
							
											if(i!==0){
													
													txt.getElementsByTagName("span")[0].className =' hide';
												var elementsAjax = doc.createElement("div");
													elementsAjax.onclick = function(){ add(this.id);};
													elementsAjax.id =  x[i].sno;
													elementsAjax.setAttribute("date-list",x[i].name);
													elementsAjax.innerHTML = x[i].name+'<p>关注：<span>'+(x[i].detail.focus_count == false ? 0 : x[i].detail.focus_count)+'</span> 人</p>';
													txt.appendChild(elementsAjax);
													
												
											}else if(i==0){
												
												if(x[i].exist == 0){
													take.parentNode.className = 'add';
													txt.getElementsByTagName("span")[0].className =' hide';
												}else if(x[i].exist == 1){
													take.parentNode.className = 'add hide';
												}
											}
										
										}
										
									}else{
										take.parentNode.className = 'add';
										txt.className = 'hide';
									}//end responseText
									
							   }else{
								
									txt.innerHTML = "<span style='color:#999;'><img src='"+G_STATIC_URL+"/common/load.gif'/> 正在加载..</span>";
								
							   }

							};
							
							XHR.send(null);
									
							
					}
					
					doc.onclick = function(){
						ajaxDate.className = 'hide';
					}
					
				},
				
				info : function(){
						var seif = this;
						mxinput['onfocus'] = function(){seif.ev()};
					
				}
				
			
			}
			
			
		},
		
		remove : function(){
		
			var o = this;
			o.parentNode.parentNode.removeChild(o.parentNode);
			
		}
	}
	
var t = new m.mx();t.info();

function add(x){

	var o = 'string' == typeof x ? document.getElementById(x) : x;
	t.app(o);
}
</script> 

<?php TPL::output('global/footer.tpl.htm'); ?>